package com.ustc.hewei.snowflakemodule.segment.entity;

import java.util.concurrent.atomic.AtomicLong;

/**
 * @author hewei
 * @version 1.0
 * @description: 号段包装类
 * @date 2022/11/16 15:04
 */

public class Segment {
    private volatile long maxId;
    private volatile int step;
    private volatile long loadingId;
    private AtomicLong value;
    private SegmentBuffer buffer;

    public long getRestSpace() {
        return this.getMaxId() - this.getValue().get();
    }

    public Segment(SegmentBuffer buffer) {
        this.buffer = buffer;
    }


    public AtomicLong getValue() {
        return value;
    }

    public long getMaxId() {
        return maxId;
    }

    public void setMaxId(long maxId) {
        this.maxId = maxId;
    }

    public int getStep() {
        return step;
    }

    public void setStep(int step) {
        this.step = step;
    }

    public long getLoadingId() {
        return loadingId;
    }

    public void setLoadingId(long loadingId) {
        this.loadingId = loadingId;
    }

    public void setValue(AtomicLong value) {
        this.value = value;
    }

    public SegmentBuffer getBuffer() {
        return buffer;
    }

    @Override
    public String toString() {
        return "Segment{" +
                "maxId=" + maxId +
                ", step=" + step +
                ", loadingId=" + loadingId +
                ", value=" + value +
                '}';
    }
}
